package com.rongshu.view.userInfo.activity;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongshu.R;
import com.rongshu.utils.Constant;
import com.rongshu.view.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

public class SafetyVerificationActivity extends BaseActivity {
    @BindView(R.id.layout_close)
    LinearLayout layout_close;
    @BindView(R.id.layout_back)
    LinearLayout layout_back;
    @BindView(R.id.txt_top_title)
    TextView txt_top_title;
    @BindView(R.id.txt_safety_verification_phone)
    TextView txt_safety_verification_phone;

    //intent
    private Intent intent = null;
    //phone
    private String phone = null;
    //request
    private final int REQUEST_CODE = 0x01;


    @Override
    protected int initLayout() {
        return R.layout.activity_safety_verification_view;
    }

    @Override
    protected void initView() {
        //getIntent
        intent = getIntent();
        if (intent != null) {
            phone = intent.getStringExtra(Constant.INTENT_DATA);
        }
        //top
        layout_back.setVisibility(View.GONE);
        layout_close.setVisibility(View.VISIBLE);
        txt_top_title.setText("安全验证");
        //phone
        if (phone.length() == 11) {
            txt_safety_verification_phone.setText(phone.substring(0, 3) + "****" + phone.substring(7, 11));
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void updateViews(boolean isRefresh) {

    }

    @OnClick({R.id.layout_close, R.id.btn_safety_verification_send})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_close:
                finish();
                break;
            case R.id.btn_safety_verification_send:
                intent = new Intent(SafetyVerificationActivity.this, SafetyVerificationCompareActivity.class);
                if (phone != null) {
                    intent.putExtra(Constant.INTENT_DATA, phone);
                }
                startActivityForResult(intent, REQUEST_CODE);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case REQUEST_CODE:
                    setResult(RESULT_OK);
                    finish();
                    break;
            }
        }
    }
}
